package com.yxj.lib_exo;

import java.util.HashSet;
import java.util.Set;

public class ExoPlayerManager {

    /**
     * 存储所有播放器
     */
    private Set<ExoPlayerView> set= new HashSet<ExoPlayerView>();

    private ExoPlayerManager() {
    }

    private static final class ManagerHolder {
        static final ExoPlayerManager manager = new ExoPlayerManager();
    }

    public static ExoPlayerManager newInstance() {
        return ManagerHolder.manager;
    }


    public void add(ExoPlayerView exoPlayerView) {
        if (exoPlayerView == null) return;
        set.add(exoPlayerView);
    }


    /**
     * @param exoPlayerView
     */
    public void play(ExoPlayerView exoPlayerView) {
        if (set.isEmpty()) return;
        for (ExoPlayerView m : set) {
            if (exoPlayerView == null || exoPlayerView != m) {
                m.pause();
            }
        }
    }


    /**
     *
     */
    public void pause() {
        if (set.isEmpty()) return;
        for (ExoPlayerView m : set) {
            m.pause();
        }
    }


    /**
     * 释放资源
     */
    public void release() {
        if (set.isEmpty()) return;
        for (ExoPlayerView m : set) {
            m.release();
        }
        set.clear();
    }
}
